package com.test;

public class Munition implements Runnable {

	private int x;
	private int y;
	private int direct;
	private int speed = 6;
	private boolean alive = true;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getDirect() {
		return direct;
	}

	public void setDirect(int direct) {
		this.direct = direct;
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public boolean isAlive() {
		return alive;
	}

	public void setAlive(boolean alive) {
		this.alive = alive;
	}

	public Munition(int x, int y, int direct) {
		this.x = x;
		this.y = y;
		this.direct = direct;

		// la musique
		AePlayWave apw = new AePlayWave("fire.wav");
		apw.start();
	}

	@Override
	public void run() {

		while (this.isAlive()) {

			try {
				Thread.sleep(50);
			} catch (Exception e) {
				e.getStackTrace();

			}

			switch (this.direct) {
			case 0:
				y -= speed;
				break;
			case 1:
				y += speed;
				break;
			case 2:
				x -= speed;
				break;
			case 3:
				x += speed;
				break;
			}

			// System.out.println(x+" || "+ y);
			// verifie si la munition touche le bord
			if (x < -3 || x > 600 || y < -3 || y > 400) {
				this.alive = false;

				break;
			}
		}
	}
}
